let wxTimer = function (initObj){
	initObj = initObj || {};
	this.beginTime = initObj.beginTime || "00:00:00";	//开始时间
	this.complete = initObj.complete; //结束任务
	this.name = initObj.name; // 计时器名字

	this.intervarID; // 清楚定时器的变量
	this.endTime; // 结束时间
}

wxTimer.prototype = {
	start:function(callBack){
		this.endTime = new Date("1970/01/01 "+this.beginTime).getTime();
		let that = this;

		let count = 0;
		function begin(){
			let tmpTime = new Date(that.endTime - 1000 * count++);
			let tmpTimeStr = tmpTime.toString().substr(16,8); // 去掉前面的年月日就剩时分秒了
			let wxTimerSecond = (tmpTime.getTime() - new Date("1970/01/01 00:00:00").getTime()) / 1000;
			console.log(wxTimerSecond)
			callBack && callBack(tmpTimeStr, wxTimerSecond)
			//结束执行函数
			if(wxTimerSecond <= 0){
				if(that.complete){
						that.complete();
				}
				that.stop();
			}
		}
		begin();
		this.intervarID = setInterval(begin,1000);
	},
	//结束
	stop:function(){
		clearInterval(this.intervarID);
	},
}

module.exports = wxTimer;
